home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / slhc.h < prev    next >
C/C++ Source or Header  |  1992-05-28  |  7KB  |  193 lines

  1. /* @(#) $Header: slhc.h,v 1.3 92/05/28 13:50:31 deyke Exp $ */
  2.  
  3. #ifndef _SLHC_H
  4. #define _SLHC_H
  5. /*
  6.  * Definitions for tcp compression routines.
  7.  *
  8.  *  Header: slcompress.h,v 1.10 89/12/31 08:53:02 van Exp $
  9.  *
  10.  * Copyright (c) 1989 Regents of the University of California.
  11.  * All rights reserved.
  12.  *
  13.  * Redistribution and use in source and binary forms are permitted
  14.  * provided that the above copyright notice and this paragraph are
  15.  * duplicated in all such forms and that any documentation,
  16.  * advertising materials, and other materials related to such
  17.  * distribution and use acknowledge that the software was developed
  18.  * by the University of California, Berkeley.  The name of the
  19.  * University may not be used to endorse or promote products derived
  20.  * from this software without specific prior written permission.
  21.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  22.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  23.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  24.  *
  25.  *      Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
  26.  *      - Initial distribution.
  27.  *
  28.  *
  29.  * modified for KA9Q Internet Software Package by
  30.  * Katie Stevens (dkstevens@ucdavis.edu)
  31.  * University of California, Davis
  32.  * Computing Services
  33.  *      - 01-31-90      initial adaptation
  34.  *
  35.  *      - Feb 1991      Bill_Simpson@um.cc.umich.edu
  36.  *                      variable number of conversation slots
  37.  *                      allow zero or one slots
  38.  *                      separate routines
  39.  *                      status display
  40.  */
  41. #ifndef _GLOBAL_H
  42. #include "global.h"
  43. #endif
  44.  
  45. #ifndef _MBUF_H
  46. #include "mbuf.h"
  47. #endif
  48.  
  49. #ifndef _IP_H
  50. #include "ip.h"
  51. #endif
  52.  
  53. #ifndef _TCP_H
  54. #include "tcp.h"
  55. #endif
  56.  
  57. /*
  58.  * Compressed packet format:
  59.  *
  60.  * The first octet contains the packet type (top 3 bits), TCP
  61.  * 'push' bit, and flags that indicate which of the 4 TCP sequence
  62.  * numbers have changed (bottom 5 bits).  The next octet is a
  63.  * conversation number that associates a saved IP/TCP header with
  64.  * the compressed packet.  The next two octets are the TCP checksum
  65.  * from the original datagram.  The next 0 to 15 octets are
  66.  * sequence number changes, one change per bit set in the header
  67.  * (there may be no changes and there are two special cases where
  68.  * the receiver implicitly knows what changed -- see below).
  69.  *
  70.  * There are 5 numbers which can change (they are always inserted
  71.  * in the following order): TCP urgent pointer, window,
  72.  * acknowlegement, sequence number and IP ID.  (The urgent pointer
  73.  * is different from the others in that its value is sent, not the
  74.  * change in value.)  Since typical use of SLIP links is biased
  75.  * toward small packets (see comments on MTU/MSS below), changes
  76.  * use a variable length coding with one octet for numbers in the
  77.  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
  78.  * range 256 - 65535 or 0.  (If the change in sequence number or
  79.  * ack is more than 65535, an uncompressed packet is sent.)
  80.  */
  81.  
  82. /*
  83.  * Packet types (must not conflict with IP protocol version)
  84.  *
  85.  * The top nibble of the first octet is the packet type.  There are
  86.  * three possible types: IP (not proto TCP or tcp with one of the
  87.  * control flags set); uncompressed TCP (a normal IP/TCP packet but
  88.  * with the 8-bit protocol field replaced by an 8-bit connection id --
  89.  * this type of packet syncs the sender & receiver); and compressed
  90.  * TCP (described above).
  91.  *
  92.  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
  93.  * is logically part of the 4-bit "changes" field that follows.  Top
  94.  * three bits are actual packet type.  For backward compatibility
  95.  * and in the interest of conserving bits, numbers are chosen so the
  96.  * IP protocol version number (4) which normally appears in this nibble
  97.  * means "IP packet".
  98.  */
  99.  
  100. /* SLIP compression masks for len/vers byte */
  101. #define SL_TYPE_IP 0x40
  102. #define SL_TYPE_UNCOMPRESSED_TCP 0x70
  103. #define SL_TYPE_COMPRESSED_TCP 0x80
  104. #define SL_TYPE_ERROR 0x00
  105.  
  106. /* Bits in first octet of compressed packet */
  107. #define NEW_C   0x40    /* flag bits for what changed in a packet */
  108. #define NEW_I   0x20
  109. #define NEW_S   0x08
  110. #define NEW_A   0x04
  111. #define NEW_W   0x02
  112. #define NEW_U   0x01
  113.  
  114. /* reserved, special-case values of above */
  115. #define SPECIAL_I (NEW_S|NEW_W|NEW_U)           /* echoed interactive traffic */
  116. #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)     /* unidirectional data */
  117. #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
  118.  
  119. #define TCP_PUSH_BIT 0x10
  120.  
  121. /*
  122.  * data type and sizes conversion assumptions:
  123.  *
  124.  *      VJ code         KA9Q style      generic
  125.  *      u_char          byte_t          unsigned char    8 bits
  126.  *      u_short         int16           unsigned short  16 bits
  127.  *      u_int           int16           unsigned short  16 bits
  128.  *      u_long          unsigned long   unsigned long   32 bits
  129.  *      int             int32           long            32 bits
  130.  */
  131.  
  132. /*
  133.  * "state" data for each active tcp conversation on the wire.  This is
  134.  * basically a copy of the entire IP/TCP header from the last packet
  135.  * we saw from the conversation together with a small identifier
  136.  * the transmit & receive ends of the line use to locate saved header.
  137.  */
  138. struct cstate {
  139.     byte_t  this;           /* connection id number (xmit) */
  140.     struct cstate *next;    /* next in ring (xmit) */
  141.     struct ip cs_ip;        /* ip/tcp hdr from most recent packet */
  142.     struct tcp cs_tcp;
  143. };
  144. #define NULLSLSTATE     (struct cstate *)0
  145.  
  146. /*
  147.  * all the state data for one serial line (we need one of these per line).
  148.  */
  149. struct slcompress {
  150.     struct cstate *tstate;  /* transmit connection states (array)*/
  151.     struct cstate *rstate;  /* receive connection states (array)*/
  152.  
  153.     byte_t tslot_limit;     /* highest transmit slot id (0-l)*/
  154.     byte_t rslot_limit;     /* highest receive slot id (0-l)*/
  155.  
  156.     byte_t xmit_oldest;     /* oldest xmit in ring */
  157.     byte_t xmit_current;    /* most recent xmit id */
  158.     byte_t recv_current;    /* most recent rcvd id */
  159.  
  160.     byte_t flags;
  161. #define SLF_TOSS        0x01    /* tossing rcvd frames until id received */
  162.  
  163.     int32 sls_o_nontcp;     /* outbound non-TCP packets */
  164.     int32 sls_o_tcp;        /* outbound TCP packets */
  165.     int32 sls_o_uncompressed;       /* outbound uncompressed packets */
  166.     int32 sls_o_compressed; /* outbound compressed packets */
  167.     int32 sls_o_searches;   /* searches for connection state */
  168.     int32 sls_o_misses;     /* times couldn't find conn. state */
  169.  
  170.     int32 sls_i_uncompressed;       /* inbound uncompressed packets */
  171.     int32 sls_i_compressed; /* inbound compressed packets */
  172.     int32 sls_i_error;      /* inbound error packets */
  173.     int32 sls_i_tossed;     /* inbound packets tossed because of error */
  174. };
  175. #define NULLSLCOMPR     (struct slcompress *)0
  176.  
  177. /* In slhc.c: */
  178. struct slcompress *slhc_init __ARGS((int rslots, int tslots));
  179. void slhc_free __ARGS((struct slcompress *comp));
  180.  
  181. int slhc_compress __ARGS((struct slcompress *comp,
  182.     struct mbuf **bpp, int compress_cid));
  183. int slhc_uncompress __ARGS((struct slcompress *comp,
  184.     struct mbuf **bpp));
  185. int slhc_remember __ARGS((struct slcompress *comp,
  186.     struct mbuf **bpp));
  187. int slhc_toss __ARGS((struct slcompress *comp));
  188.  
  189. void slhc_i_status __ARGS((struct slcompress *comp));
  190. void slhc_o_status __ARGS((struct slcompress *comp));
  191.  
  192. #endif  /* _SLHC_H */
  193.